home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************
- ADOBE SYSTEMS INCORPORATED
- Copyright 2002 Adobe Systems Incorporated
- All Rights Reserved
-
- NOTICE: Adobe permits you to use, modify, and distribute this
- file in accordance with the terms of the Adobe license agreement
- accompanying it. If you have received this file from a source
- other than Adobe, then your use, modification, or distribution
- of it requires the prior written permission of Adobe.
- ***************************************************************/
- /***************************************************************
- Author: Mary Obelnicki
- ***************************************************************/
-
- /***************************************************************
-
- This script is used to create a key framed animation of an array
- of objects traveling along a bezier curve path.
-
- To use:
- Create a path. Group it with one or more objects. The
- objects will be animated in sequence. With the group
- selected, execute the script.
-
-
- Function:
- animateGroupToCurve(group, pathIndex, frames, track, stagger)
-
- Arguments:
- <group> LMGroupObject: a group with both the object to
- animate and the path to animate it on the path used
- as the base for the animation will be the top-most
- path object in the group, the object will be the
- top-most object that is not the animation path
- <pathIndex> integer: which path in the path object to use,
- this value is usually 0.
- <frames> integer: how many key frames of animation to create
- <track> boolean: the rotation of the object track the
- curve. true = yes, false = no
-
- ***************************************************************/
-
- #include "../../Include/CubicBezier.js"
-
- /***************************************************************
- To change the behavior of this script,
- make your changes below
- ***************************************************************/
-
- animateGroupToCurve(application.currentComposition.objects[0], 0, 24, true, 1);
-
- /***************************************************************
- DO NOT EDIT BELOW THIS LINE
- ***************************************************************/
-
- function animateToCurve(object, curves, frames, track)
- //object: the object that will be animated
- //curves: an array of parameterize curves. Each curve must have a function pointAt()
- // and be parameterize for 0 <= t <= 1.
- //frames: how many frames the animation will occupy.
- // if you want an animation that takes 2 seconds at 12 fps, frames must equal 25.
- //track: a boolean. If true, <objects>'s rotation will follow changes
- // in the angle of the line tangent to the path
- {
-
- if (curves.length < 1)
- return;
-
- frames--;
- var startFrame = object.currentFrame;
- var tPerFrame = curves.length/frames;
- var oriObjRot;
- var oriPathAngle;
-
- object.stopwatch.position = true;
-
- if(track)
- {
- object.stopwatch.rotation = true;
- oriObjRot = object.rotation;
- var vectorOne = curves[0].pointAt(0.0);
- var vectorTwo = curves[0].pointAt(0.001);
- oriPathAngle = Vector.subtract(vectorTwo, vectorOne).polarAngle();
- }
-
- var curveIndex;
- for(curveIndex = 0; curveIndex < curves.length; curveIndex++)
- {
- var firstFrame = Math.ceil(curveIndex*frames/curves.length);
- var lastFrame = Math.floor((curveIndex+1)*frames/curves.length);
- var frame;
-
- for(frame = firstFrame; frame <= lastFrame ; frame++)
- {
- object.currentFrame = startFrame +frame;
- var currentT = (frame*tPerFrame) - curveIndex;
- var currentPoint = curves[curveIndex].pointAt(currentT);
- object.position.x = currentPoint.x;
- object.position.y = currentPoint.y;
-
- if(track)
- {
- //get two points on the curve
- //currentPoint is the first point
- //get the angle tangent to the curve
- var otherPoint;
- var currentPathAngle;
- if((currentT +.01)>1.0)
- {
- otherPoint = curves[curveIndex].pointAt(currentT - 0.001);
- currentPathAngle = Vector.subtract(currentPoint, otherPoint).polarAngle();
- // currentPathAngle = getPolarAngle(otherPoint, currentPoint);
- }
- else
- {
- otherPoint = curves[curveIndex].pointAt(currentT + 0.001);
- currentPathAngle = Vector.subtract(otherPoint, currentPoint).polarAngle();
- // currentPathAngle = getPolarAngle(currentPoint, otherPoint);
- }
- //set the angle for the object
- object.rotation = oriObjRot + (currentPathAngle - oriPathAngle);
-
- }
- }
- }
- }
-
- function animateGroupToCurve(group, pathIndex, frames, track, stagger){
- //group: a group with both the object to animate and the path to animate it on
- // the path used as the base for the animation will be the top-most path object in
- // the group, the object will be the top-most object that is not the animation path
- //pathIndex: which path in the path object to use, this value is usually 0.
- //frames: how many key frames of animation to create
- //track: should the rotation of the object track the curve. true = yes, false = no
-
- //find the pathobject
- var pathObjectIndex;
- var objectIndex;
- var i;
- var startFrame = group.currentFrame;
- var objectCount = 0;
- for (i = 0; i < group.objects.length; i++)
- {
- if (group.objects[i].paths) // only a path object has paths
- {
- pathObjectIndex = i;
- break;
- }
- }
-
- var beziers = CubicBezier.pathToBeziers(group.objects[pathObjectIndex], pathIndex);
- //animate everything put the first path object
- for (i = 0; i < group.objects.length; i++)
- {
- if (i != pathObjectIndex)
- {
- group.objects[i].currentFrame = startFrame + objectCount*stagger;
- animateToCurve(group.objects[i], beziers, frames, track);
- objectCount++;
- }
- }
- }
-
- function curveTextEffect(group, path, pathframes, endframes, track, stagger, forward, startRot){
-
- //find the pathobject
- var pathObjectIndex;
- var objectIndex;
- var i;
- var startFrame = group.currentFrame;
- var endFrame = (startFrame - 1) + pathframes + endframes;
- var objectCount = 0;
- for (i = 0; i < group.objects.length; i++)
- {
- if (group.objects[i].paths) // only a path object has paths
- {
- pathObjectIndex = i;
- break;
- }
- }
- //save all the object offsets from the first object that is not the animation path;
- var baseIndex;
- if(forward)
- {
- if (pathObjectIndex == (group.objects.length - 1))
- baseIndex = group.objects.length-2;
- else
- baseIndex = group.objects.length-1;
- }
- else
- {
- if (pathObjectIndex == 0)
- baseIndex = 1;
- else
- baseIndex = 0;
- }
-
- var xoffset = new Array;
- var yoffset = new Array;
- var oriRot = new Array;
- for (i = 0; i < group.objects.length; i++)
- {
- xoffset[i] = group.objects[i].position.x - group.objects[baseIndex].position.x;
- yoffset[i] = group.objects[i].position.y - group.objects[baseIndex].position.y;
- oriRot[i] = group.objects[i].rotation;
- }
-
- //find the object
- for (i = 0; i < group.objects.length; i++)
- {
- var j;
- if(forward)
- j = i;
- else
- j = group.objects.length - 1 - i;
- if (j != pathObjectIndex)
- {
- group.objects[j].currentFrame = startFrame + objectCount*stagger;
- group.objects[j].startFrame = group.objects[j].currentFrame;
- group.objects[j].rotation = startRot;
- animateToCurve(group.objects[j], group.objects[pathObjectIndex], path, pathframes, track);
-
-
- //put the object back in place
- group.objects[j].currentFrame = endFrame + objectCount*stagger;
- group.objects[j].position.x = group.objects[j].position.x + xoffset[j];
- group.objects[j].position.y = group.objects[j].position.y + yoffset[j];
- group.objects[j].rotation = oriRot[j];
- objectCount++;
- }
- }
- }
-
-